﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

using NHibernate;

using ZQNB.BaseLib.Users.Impl;
using ZQNB.Common;
using ZQNB.Common.NHExtensions;
using ZQNB.Entity.Users;

namespace ZQNB.BaseLib.Users.TeacherServiceTest
{
    //对于带有 AssemblyInitialize 属性标记的方法，仅当该方法属于带有 TestClass 属性标记的类的成员时，测试引擎才会运行它
    [TestClass]
    public class WhenCreateTeacher
    {
        [TestMethod]
        public void NotExistShouldExist()
        {
            ISession session = SqlUtHelper.Instance.OpenSession();
            TeacherService service = new TeacherService(session);

            var teacherExist = TestInitData.ExistTeacher;
            Teacher newTeacher = TestInitData.Clone(teacherExist);

            newTeacher.AddTeacher(new TeacherSubject() { GradeCode = "1" });
            newTeacher.AddTeacher(new TeacherSubject() { GradeCode = "2" });
            newTeacher.AddTeacher(new TeacherSubject() { GradeCode = "3" });

            MessageResult messageResult = service.SaveOrUpdate(newTeacher);

            Assert.IsTrue(messageResult.Success);

            //删除
            newTeacher.TeacherSubjects.RemoveAt(0);
            MessageResult messageResult2 = service.SaveOrUpdate(newTeacher);
            Assert.IsTrue(messageResult2.Success);

            //查询
            var query = service.GetBySubject("2");
            Assert.AreEqual(1, query.Count);
        }
    }
}